package com.yuxi;

/**
 * Created by yuxi on 17/1/26.
 */
public class MyThread {
    public static void main(String[] args) {
//        MyThreadOne myThreadOne1 = new MyThreadOne();
//        myThreadOne1.start();
//
//        MyThreadOne myThreadOne2 = new MyThreadOne();
//        myThreadOne2.start();
//
//        MyThreadOne myThreadOne3 = new MyThreadOne();
//        myThreadOne3.start();
        MyThreadTwo myThreadTwo = new MyThreadTwo();
        Thread thread1 = new Thread(myThreadTwo);
        Thread thread2 = new Thread(myThreadTwo);
        Thread thread3 = new Thread(myThreadTwo);
        thread2.start();
        thread1.start();
        thread3.start();
    }

    static class MyThreadOne extends Thread {
        private int ticket=10;
        public void run() {
            for (int i = 0; i < 20; i++) {
                if (ticket>0) {
                    System.out.println("当前" + Thread.currentThread().getName() + "买了" + (ticket--) + "票");
                }
            }
        }
    }


    static class MyThreadTwo implements Runnable {
        private int ticket=10;
        public void run() {
            for (int i = 0; i < 20; i++) {
                if (ticket>0) {
                    System.out.println("当前" + Thread.currentThread().getName() + "买了" + (ticket--) + "票");
                }
            }
        }
    }


}
